package is.xdumper;

import is.bean.entity.preference.PreferenceBeanRemoteHome;
import java.rmi.RemoteException;
import javax.ejb.FinderException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

/**
 *
 * @author aspr0
 */
public class XdumperConf
{
    /**
     * Relative to "out" catalog
     */
    public static final String PATH_DUMP_XSLT_RELATIVE = "xsd-xslt/dump.xsl";

    public static String getPathDumpSchema() throws NamingException, RemoteException, XdumperNoPathException
    {
        String pathDumpSchema = "5_isbdx/5_isbdx-war_war/xdumper/out/xsd-xslt/dump.xsd";
        return getDap() + pathDumpSchema;
    }

    /**
     * Get Deployed Application Path
     *
     * @return
     */
    public static String getDap() throws NamingException, RemoteException, XdumperNoPathException
    {
        Object pbRef = new InitialContext().lookup("ejb/PreferenceBean");
        PreferenceBeanRemoteHome preferenceHome =
                (PreferenceBeanRemoteHome) PortableRemoteObject.narrow(pbRef, PreferenceBeanRemoteHome.class);

        String dap;
        try
        {
            dap = preferenceHome.findByPrimaryKey("dap").getData().getValue();
        }
        catch (FinderException ex)
        {
            throw new XdumperNoPathException();
        }

        return dap;
    }
}
